#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e4+10,MAXL=1e6+10;
int n,cnt,len,lena;
char a[MAXL],temp[51];
struct point
{
    int fail,c[26],count;
}p[MAXL];
queue<int>q;
void insert()
{
    int u=0;
    p[0].fail=0;
    for(int i=0;i<len;++i)
    {
        int k=temp[i]-'a';
        if(!p[u].c[k])p[u].c[k]=++cnt;
        u=p[u].c[k];
        if(i==len-1)++p[u].count;
    }
    return;
}
void cal_fail()
{
    q.push(0);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int i=0;i<26;++i)
        {
            if(!p[u].c[i])continue;
            int k=p[u].fail;
            while(k&&!p[k].c[i])k=p[k].fail;
            if(u!=k)p[p[u].c[i]].fail=p[k].c[i];
            q.push(p[u].c[i]);
        }
    }
    return;
}
int query()
{
    int i=0,j=0,ans=0;
    while(i<lena)
    {
        int k=a[i]-'a';
        while(j&&!p[j].c[k])j=p[j].fail;
        j=p[j].c[k];
		int temp=j;
        while(temp&&p[temp].count)
        {
            ans+=p[temp].count;
            p[temp].count=0;
            temp=p[temp].fail;
        }
        ++i;
    }
    return ans;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        memset(p,0,sizeof(p));
        cnt=0;
        int n;
        scanf("%d",&n);
        while(n--)
        {
            scanf("%s",temp);
            len=strlen(temp);
            insert();
        }
        scanf("%s",a);
        lena=strlen(a);
        cal_fail();
        printf("%d\n",query());
    }
    return 0;
}
